package com.lizardmind.haofudoctor.other.rongYun

import android.content.Context
import android.text.Spannable
import android.text.SpannableString
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.linxiao.framework.util.toasts
import com.lizardmind.haofudoctor.R
import com.lizardmind.haofudoctor.manager.setImageUrl
import com.lizardmind.haofudoctor.other.OnClickRongDiagnoseEvent
import com.lizardmind.haofudoctor.other.OnClickRongFanganEvent
import com.lizardmind.haofudoctor.other.OnClickRongVisitEvent
import com.lizardmind.haofudoctor.ui.other.PatientsEduWebActivity
import io.rong.imkit.model.ProviderTag
import io.rong.imkit.model.UIMessage
import io.rong.imkit.widget.provider.IContainerItemProvider
import io.rong.imlib.model.Message
import org.greenrobot.eventbus.EventBus
import org.jetbrains.anko.find
import org.jetbrains.anko.startActivity

/**
 * 患者教育布局
 * Created by Extends on 2017/12/4 16:12
 */
@ProviderTag(messageContent = PatientsEducationMessage::class)
class PatientsEducationItemProvider : IContainerItemProvider.MessageProvider<PatientsEducationMessage>() {
    override fun onItemClick(p0: View, p1: Int, p2: PatientsEducationMessage, p3: UIMessage) {
        toasts("暂时跳往PatientsEduWebActivity")
        p0.context.startActivity<PatientsEduWebActivity>("url" to p2.url)
    }

    override fun bindView(v: View, position: Int, content: PatientsEducationMessage, message: UIMessage) {
        val holder = v.tag as ViewHolder
        if(message.messageDirection == Message.MessageDirection.SEND){//消息方向，自己发送的
            v.setBackgroundResource(R.drawable.rc_ic_bubble_right_file)
        }else {
            v.setBackgroundResource(R.drawable.rc_ic_bubble_left_file)
        }
        holder.title?.text = content.title
        holder.content?.text = content.content
        if(content.img!=null && content.img.isNotEmpty()){
            holder.img?.setImageUrl(content.img)
            holder.img?.visibility = View.VISIBLE
        }else{
            holder.img?.visibility = View.GONE
        }
    }

    override fun getContentSummary(p0: PatientsEducationMessage): Spannable {
        return SpannableString("[患教消息]")
    }

    override fun newView(p0: Context, p1: ViewGroup): View {
        val view = LayoutInflater.from(p0).inflate(R.layout.ry_item_patients_education,p1,false)
        val holder = ViewHolder()
        holder.title = view.find(R.id.ripe_title)
        holder.content = view.find(R.id.ripe_content)
        holder.img = view.find(R.id.ripe_img)
        view.tag = holder
        return view
    }

    class ViewHolder{
        var title: TextView?=null
        var content: TextView?=null
        var img:ImageView?=null
    }
}